//
// Created by 党清浩 on 2021/10/10.
//

#include <stdio.h>
/*定义数组长度*/
#define MAX_SIZE 255
typedef int ElementType;

typedef struct {
    ElementType elem[MAX_SIZE];
    int len;
} SeqList;

/*声明输入数组*/
void scanfLinkList(SeqList *list, int len);

/*声明合并数组*/
void mergeLinkList(SeqList *La, SeqList *Lb, SeqList *Lc);

/*声明输出数组*/
void printLinkList(SeqList *list);

int main() {
    SeqList la, lb, lc;
    la.len = 5;
    lb.len = 6;
    lc.len = la.len + lb.len;


    scanfLinkList(&la, la.len);
    scanfLinkList(&lb, lb.len);


    printf("There are 5 elements in La,which are:");
    printLinkList(&la);
    printf("\nThere are 6 elements in Lb,which are:");
    printLinkList(&lb);
    printf("\nThere are 11 elements in Lc,which are:");
    /*调用合并方法*/
    mergeLinkList(&la, &lb, &lc);
    printLinkList(&lc);
    return 0;
}

/*  输入数组la，lb  */
void scanfLinkList(SeqList *list, int len) {
    int i;
    scanf("%d", &list->elem[0]);
    for (i = 1; i < len; i++) {
        do {
            scanf("%d", &list->elem[i]);

        } while (list->elem[i] < list->elem[i - 1]);
    }
}
/*合并方法*/
void mergeLinkList(SeqList *LA, SeqList *LB, SeqList *LC) {
    int i = 0, j = 0, k = 0;
    while (i <= LA->len && j <= LB->len) {
        if (LA->elem[i] <= LB->elem[j]) {
            LC->elem[k] = LA->elem[i];
            i++;
            k++;
        } else {
            LC->elem[k] = LB->elem[j];
            j++;
            k++;
        }
    }
    while (i <= LA->len) {
        LC->elem[k] = LA->elem[i];
        i++;
        k++;
    }
    while (j <= LB->len) {
        LC->elem[k] = LB->elem[j];
        j++;
        k++;
    }
    LC->len = LA->len + LB->len + 1;
}

/*输出顺序表*/
void printLinkList(SeqList *list) {
    int i;
    for (i = 0; i < list->len; i++) {
        if (list->elem[i] == 0) {
            continue;
        } else {
            printf("%-4d", list->elem[i]);
        }
    }
}


